package com.dailywork.basepro.thread.container;

import java.util.concurrent.DelayQueue;

/**
 * DelayQueueʾ��
 *
 * @author lhy @ time 2018.01.02
 */
public class WangBa implements Runnable {

    private DelayQueue<WangMin> queue = new DelayQueue<WangMin>();
    public boolean yinyue = true;

    public void Shangji(String name, String id, int money) {
        WangMin man = new WangMin(name, id, 1000 * money + System.currentTimeMillis());
        System.out.println(
                "����" + man.getName() + "���֤" + man.getId() + "��Ǯ" + money + "��,��ʼ�ϻ�...");
        this.queue.add(man);
    }

    public void Xiaji(WangMin man) {
        System.out.println("����" + man.getName() + "���֤" + man.getId() + "ʱ�䵽�»�");
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        while (yinyue) {
            try {
                WangMin man = queue.take();
                Xiaji(man);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            System.out.println("���ɿ�ʼӪҵ");
            WangBa haige = new WangBa();
            Thread shangwang = new Thread(haige);
            shangwang.start();

            haige.Shangji("yangxu", "123", 1);
            haige.Shangji("yangming", "123", 5);
            haige.Shangji("yangge", "123", 10);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
